<?php
if (!defined("BASEPATH")) exit("No direct script access allowed");

class Ent2cat extends MY_Model {

	function __construct() {
		parent::__construct();
		$this->tableName = "ent2cat";
		$this->prefix = "e2c";
	}

	function getEnt2cat($where = NULL) {
		$qs =	"
					select
						e2c_id, e2c_ent_id, e2c_cat_id, e2c_entity, e2c_int, e2c_text, e2c_temp, e2c_temp_flag, e2c_lastupd, cat_name, cat_type
					from
						".$this->db->dbprefix.$this->tableName."
						join ".$this->db->dbprefix."category on cat_id = e2c_cat_id and e2c_entity = cat_entity and e2c_del = 0
					where
						e2c_del = 0".((!is_null($where))?(" and ".$where):(""))."
					order by
						cat_order
					";
		$result = $this->db->query($qs);
		$getEnt2cat = array();
		if($result->num_rows()) {
			foreach ($result->result() as $row) {
				$getEnt2cat[$row->e2c_cat_id]["e2cId"] = $row->e2c_id;
				$getEnt2cat[$row->e2c_cat_id]["e2cEntId"] = $row->e2c_ent_id;
				$getEnt2cat[$row->e2c_cat_id]["e2cEntity"] = $row->e2c_entity;
				$getEnt2cat[$row->e2c_cat_id]["e2cInt"] = $row->e2c_int;
				$getEnt2cat[$row->e2c_cat_id]["e2cText"] = $row->e2c_text;
				$getEnt2cat[$row->e2c_cat_id]["e2cTemp"] = $row->e2c_temp;
				$getEnt2cat[$row->e2c_cat_id]["e2cTempFlag"] = $row->e2c_temp_flag;
				$getEnt2cat[$row->e2c_cat_id]["e2cLastupd"] = $row->e2c_lastupd;
				$getEnt2cat[$row->e2c_cat_id]["catName"] = $row->cat_name;
				$getEnt2cat[$row->e2c_cat_id]["catType"] = $row->cat_type;

				if(defined("STUDY_PREVIEW") and $row->e2c_temp != "") {
					$getEnt2cat[$row->e2c_cat_id]["e2cInt"] = ((is_numeric($row->e2c_temp))?($row->e2c_temp):(NULL));
					$getEnt2cat[$row->e2c_cat_id]["e2cText"] = ((!is_numeric($row->e2c_temp))?($row->e2c_temp):(NULL));
				}

			}
		}

		return $getEnt2cat;
	}

}